import {
  createQueryUserInfoStatement,
  createAddMarkInfoStatement,
  createRealTimeMonitoring,
  createEditUserInfoStatement,
} from './statements';
import { getDB } from '../../db';

/**
 * 查询用户登录信息
 */
export const queryUserinfo = async (data: any) => {
  const queryStatement = createQueryUserInfoStatement();
  return await queryStatement.all(data);
};

/**
 * TODO 待删除
 * 添加视频标注剪辑与编辑模块
 * @param markInfoInfos 视频标注信息
 */
export const addMarkInfo = async (markInfoInfos: LX.DBService.MarkInfoInfo[]) => {
  const insertStatement = createAddMarkInfoStatement();
  const db = getDB();
  db.transaction(async (markInfoInfos: LX.DBService.MarkInfoInfo[]) => {
    for (const markInfoInfo of markInfoInfos) {
      insertStatement.run({
        id: markInfoInfo.id,
        videoInfoId: markInfoInfo.videoInfoId,
        startTime: markInfoInfo.startTime,
        endTime: markInfoInfo.endTime,
        label: markInfoInfo.label,
        describe: markInfoInfo.describe,
        channel: markInfoInfo.channel,
        status: markInfoInfo.status,
        createTime: markInfoInfo.createTime,
        createUser: markInfoInfo.createUser,
      });
    }
  })(markInfoInfos);
};

/**
 * TODO 待删除
 * 添加视频标注实时监控模块
 * @param markInfoInfos 视频标注信息
 */
export const addRealTimeMarkInfo = (markInfoInfos: LX.DBService.MarkRealTimeInfoInfo[]) => {
  const insertStatement = createRealTimeMonitoring();
  const db = getDB();
  db.transaction((markInfoInfos: LX.DBService.MarkRealTimeInfoInfo[]) => {
    for (const markInfoInfo of markInfoInfos) {
      insertStatement.run({
        id: markInfoInfo.id,
        startTime: markInfoInfo.startTime,
        endTime: markInfoInfo.endTime,
        label: markInfoInfo.label,
        describe: markInfoInfo.describe,
        channel: markInfoInfo.channel,
        status: markInfoInfo.status,
        createTime: markInfoInfo.createTime,
        createUser: markInfoInfo.createUser,
      });
    }
  })(markInfoInfos);
};

/**
 * 更新密码
 */
export const updateUserPassword = (data: LX.DBService.EditUserInfo) => {
  console.log(data);
  const statements = createEditUserInfoStatement();
  const db = getDB();
  db.transaction((data) => {
    statements.run(data);
  })(data);
};
